import sys

from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
from PyQt5.QAxContainer import QAxWidget
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage, QWebEngineSettings
from PyQt5.QtWidgets import QMainWindow, QApplication


class WebEngineView(QMainWindow):
    def __init__(self, url: str, title: str):
        super(WebEngineView, self).__init__()
        self.setWindowTitle(title)
        self.resize(960, 540)
        # 新建一个QWebEngineView()对象
        self.qwebengine = QWebEngineView(self)
        profile = QWebEngineProfile("my_profile", self.qwebengine)
        profile.defaultProfile().setPersistentCookiesPolicy(QWebEngineProfile.ForcePersistentCookies)
        webpage = QWebEnginePage(profile, self.qwebengine)
        webpage.settings().setAttribute(QWebEngineSettings.PlaybackRequiresUserGesture, False)

        self.qwebengine.setPage(webpage)
        # 设置网页在窗口中显示的位置和大小
        self.qwebengine.setGeometry(0, 0, 960, 540)
        # 在QWebEngineView中加载网址
        self.qwebengine.load(QUrl(url))


class IEView(QMainWindow):
    def __init__(self, url: str, title: str):
        super(IEView, self).__init__()
        self.resize(800, 600)
        self.setWindowTitle(title)
        self.ocx = QAxWidget(self)
        self.ocx.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}")
        self.setCentralWidget(self.ocx)
        self.ocx.dynamicCall("Navigate(const QString&)", url)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ui = IEView("https://www.bilibili.com/video/BV1vx411E7Mb", "Title")
    # ui = IEView("http://localhost:3333/test/multimedia#013800138999-2", "Title")
    ui.show()
    sys.exit(app.exec_())
